package ooday03;

public class RefArrayDemo {
    public static void main(String[] args) {
        Dog[] dogs = new  Dog[3];
        dogs[0] = new Dog("旺财", 3, "黄色");
        dogs[1] = new Dog("大黄", 2, "白色");
        dogs[2] = new Dog("小黄", 1, "黑色");

        dogs[2].age = 3;
        dogs[1].swim();
        dogs[2].eat();

        //遍历数组
        for(int i = 0; i < dogs.length; i++){
            System.out.println(dogs[i].name);
            dogs[i].eat();
            dogs[i].drink();
            dogs[i].swim();
        }

        Fish[] fishs = new Fish[2];
        fishs[0] = new Fish("鱼儿", 1, "嘿色");
        fishs[1] = new Fish("小鱼", 1, "金色");
        for(int i = 0; i < fishs.length; i++){
            System.out.println(fishs[i].name);
            fishs[i].eat();
            fishs[i].drink();
        }

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("鸡哥", 1, "白色");
        chicks[1] = new Chick("坤哥", 1, "黑色");
        for(int i = 0; i < chicks.length; i++){
            System.out.println(chicks[i].age);
            chicks[i].eat();
        }





        /*
        //声明了一个Dog型的数组叫dogs，包含三个元素，每个元素都是Dog，默认值是 null。
        Dog[] dogs = new Dog[3];
        Chick[] chicks = new Chick[2];
        Fish[] fishs = new Fish[4];

         */
    }
}
